package com.android.billingclient.api;

import android.os.Bundle;
import c.a.a.a.a;
import com.android.billingclient.api.g;
import java.util.ArrayList;

final class d0 {
    static g a(Bundle bundle, String str, String str2) {
        String format;
        g gVar = b0.j;
        if (bundle == null) {
            format = String.format("%s got null owned items list", new Object[]{str2});
        } else {
            int h = a.h(bundle, str);
            String g = a.g(bundle, str);
            g.a b2 = g.b();
            b2.c(h);
            b2.b(g);
            g a2 = b2.a();
            if (h != 0) {
                a.k(str, String.format("%s failed. Response code: %s", new Object[]{str2, Integer.valueOf(h)}));
                return a2;
            } else if (!bundle.containsKey("INAPP_PURCHASE_ITEM_LIST") || !bundle.containsKey("INAPP_PURCHASE_DATA_LIST") || !bundle.containsKey("INAPP_DATA_SIGNATURE_LIST")) {
                format = String.format("Bundle returned from %s doesn't contain required fields.", new Object[]{str2});
            } else {
                ArrayList<String> stringArrayList = bundle.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                ArrayList<String> stringArrayList2 = bundle.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
                ArrayList<String> stringArrayList3 = bundle.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
                if (stringArrayList == null) {
                    format = String.format("Bundle returned from %s contains null SKUs list.", new Object[]{str2});
                } else if (stringArrayList2 == null) {
                    format = String.format("Bundle returned from %s contains null purchases list.", new Object[]{str2});
                } else if (stringArrayList3 != null) {
                    return b0.m;
                } else {
                    format = String.format("Bundle returned from %s contains null signatures list.", new Object[]{str2});
                }
            }
        }
        a.k(str, format);
        return gVar;
    }
}
